package com.lagou.boot;

import com.lagou.service.IUserService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @ClassName ServerBootStartConfig
 * @Description TODO
 * @Author chenshiyan
 * @Date 2021/2/2 15:29
 */
@Component
@Configuration
public class ServerBootStartConfig implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ServerBootStartConfig.applicationContext = applicationContext;

        IUserService userService = ServerBootStartConfig.applicationContext.getBean(IUserService.class);
        try {
            userService.startServer("127.0.0.1",8999);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static Object getApplication(String name){
        return applicationContext.getBean(name);
    }

    public static Object getApplication(Class name){
        return applicationContext.getBean(name);
    }


}
